<template>
  <div>
    <transition
      name="slide-fade" mode="out-in"
      >
    <custom-container v-if="!detailVisible">
    <custom-container-header no-spacing>
      <el-form :model="filters" ref="form" :disabled="loading"
               inline size="medium"
               @submit.native.prevent="getAll"
               class="width-100"
      >
        <el-form-item label="查询时间:">
          <el-date-picker
            v-model="filters.date"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="{disabledDate: beforeToday.disabledDate}"
            value-format="timestamp"
            :default-time="['00:00:00', '23:59:59']"
          >
          </el-date-picker>
        </el-form-item>
        <!--<el-form-item>-->
          <!--<el-button type="primary" native-type="submit">查询</el-button>-->
        <!--</el-form-item>-->

        <el-form-item class="float-right">
          <custom-button-group v-model="time">
            <custom-button v-for="period in consts.TIME_PERIOD" :key="period.value" :label="period.value">
              {{period.title}}
            </custom-button>
          </custom-button-group>
        </el-form-item>
      </el-form>
    </custom-container-header>
    <custom-container-body>
      <el-table :data="cList" :loading="loading" element-loading-text="加载中..." border border-radius
                :summary-method="getSummaries"
                show-summary
                @sort-change="sortChange"
      >
        <el-table-column
          align="center"
          prop="game"
          label="游戏名称">
        </el-table-column>
        <el-table-column
          align="center"
          label="投注人数">
          <template slot-scope="{row}">
            <el-button type="link" size="small" @click="openDetail({props: {row, filters}})">
              {{row.users}}
            </el-button>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="投注金额">
          <template slot-scope="{row}">
            {{row.amount | currency}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="派彩金额">
          <template slot-scope="{row}">
            {{row.prize | currency}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="有效投注金额">
          <template slot-scope="{row}">
            {{row.effectAmount | currency}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="公司总盈利">
          <template slot-scope="{row}">
            <money-text :negate="true" :value="row.win"></money-text>
          </template>
        </el-table-column>


        <template slot="empty">
          <div class="el-table__empty">
            <svg-icon class="el-table__empty-icon" icon-class="grid-empty-2"></svg-icon>
            <div class="el-table-text">暂无数据</div>
          </div>
        </template>
      </el-table>
    </custom-container-body>
    </custom-container>
    <betting-detail
      :info="detailProps"
      v-else
    ></betting-detail>
    </transition>
  </div>
</template>

<script type="text/jsx">

  import {gameReportApi as getApi} from '@/services/api/report';

  import {detailContent, grid, pickerOption} from '@/build';
  import BettingDetail from "@/views/report-center/game-win-lose/betting-detail";

  export default {

    name: "game-win-lose",

    components: {BettingDetail},

    mixins: [grid, pickerOption, detailContent],

    data() {
      return {
        filters: {
          date: undefined,
        },
        summariesText: '汇总',
        time: consts.TODAY,
        tableData: {
          list: [],
          total: 0,
        },
        statistic: [
          {
            index: 1,
            prop: 'tableData.sum.users',
          },
          {
            index: 2,
            prop: 'tableData.sum.amount',
            format: (value) => {
              return <div>{_.currency(value)}</div>;
            }
          },
          {
            index: 3,
            prop: 'tableData.sum.prize',
            format: (value) => {
              return <div>{_.currency(value)}</div>;
            }
          },
          {
            index: 4,
            prop: 'tableData.sum.effectAmount',
            format: (value) => {
              return <div>{_.currency(value)}</div>;
            }
          },
          {
            index: 5,
            prop: 'tableData.sum.win',
            format: (value) => {
              return <money-text negate={true} value={value}></money-text>;
            }
          },
        ]
      };
    },

    watch: {
      'filters.date'() {
        this.gridSearch();
      }
    },

    computed: {
      cList() {
        return _(this.tableData.list)
          .filter(info => {
            if (info.game === '188体育') {
              info.game = '贝博体育';
            }

            return !_.includes(['棋牌开元'], info.game);
          })
          .value();
      }
    },

    mounted() {
      this.bindGet(getApi, 'tableData', {
        action: 'getGrid',
        sendingData: 'filters',
      });
    }
  };

</script>

